using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class PlayerStateBase : EntityStateBase
{
    protected Player player { get; private set; }
    protected PlayerInput input;
    protected PlayerSkillManager skillManager;
    public PlayerStateBase(Player player, StateMachine stateMachine, string animName) : base(stateMachine, animName)
    {
        this.player = player;
        animator = player.animator;
        rb = player.rb;
        input = player.playerInput;
        entityStat = player.entityStat;
        skillManager = player.playerSkillManager;
    }
    public override void Update()
    {
        base.Update();
        if (input.Player.Skill_Domain.WasPressedThisFrame() && skillManager.skillDomainExpansion.CanUseSkill())
        {
            if (skillManager.skillDomainExpansion.CanMoveToSky())
                stateMachine.ChangeState(player.domainExpansionState);
            else
                skillManager.skillDomainExpansion.CreateDomainExpansion();
                
            //更新冷却
            skillManager.skillDomainExpansion.SetSkillOnCoolDown();
        }

        if (input.Player.Dash.WasPressedThisFrame() && CanDash())
        {
            skillManager.skillDash.SetSkillOnCoolDown();
            stateMachine.ChangeState(player.dashState);
        }
    }
    protected override void UpdateAnimationParameters()
    {
        base.UpdateAnimationParameters();
        animator.SetFloat("yVelocity", rb.velocity.y);
    }
    private bool CanDash()
    {
        if (skillManager.skillDash.CanUseSkill() == false)
            return false;
        if (stateMachine.currentState == player.dashState ||
            stateMachine.currentState == player.domainExpansionState ||
            stateMachine.currentState == player.counterAttackState ||
            player.IsWall)
            return false;
        return true;
    }
}
